const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    type:1,
    lists:"",
  },
  onLoad: function (options) {
    this.taskday()
    if(options.parentid){
      app.globalData.parentid=options.parentid
    }
  },
  onPullDownRefresh(){
    this.setData({
      lists:"",
    })
    this.taskday()
    wx.stopPullDownRefresh()
  },
  change(e){
    this.setData({
      type:e.currentTarget.dataset.type
    })
    this.taskday()
  },
  taskday(){
    if(this.data.type==1){
      Controller.taskday().then(res=>{
        if(res.data.baseData){
          this.setData({
            lists:res.data.baseData,
          })
        }
      })
    }else{
      Controller.taskother().then(res=>{
        if(res.data.baseData){
          this.setData({
            lists:res.data.baseData,
          })
        }
      })
    }
  },
  sign(){
    Controller.action({type:7}).then(res=>{
       wx.showToast({
          title:"签到成功"
        })
       this.taskday()
    })
  },
  golink(e){
    if (!wx.getStorageSync('logintoken')) {
      app.ToLogin(true)
      return
    }
    var url=e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url
    })
  },
  gomall(e){
    if (!wx.getStorageSync('logintoken')) {
      app.ToLogin(true)
      return
    }
    var url=e.currentTarget.dataset.url;
    wx.switchTab({
      url: url
    })
  },
  onShareAppMessage: function (e) {
    let title = this.data.title || '';
    let imageUrl = this.data.shareimg || '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
  onShareTimeline: function(res){
    let title = this.data.title || '';
    let imageUrl = this.data.shareimg || '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },

})